(function() {
	// 管子类
	var Pipe = window.Pipe = function() {
		// 引入图片
		this.imagedown = game.r.pipe_down;
		this.imageup = game.r.pipe_up;
		// 自己的位置,是屏幕的最右边
		this.x = game.canvas.width;
		// 总高度
		this.allheight = game.canvas.height * 0.78;
		// 空隙
		this.interspace = 120;
		// 图片高度
		this.picheight = 320;
		// 随机一个上管子的高度,保证至少有150高度
		this.dnwnheight = 150 + parseInt(Math.random() * (this.picheight - 150));
		// 下管子
		this.upheight = this.allheight - this.dnwnheight - this.interspace;
		// 是否已经成功通过
		this.alreadyPass = false;
		// 将自己推入管子数组
		game.pipe_Arr.push(this);

	}
	// 更新
	Pipe.prototype.updata = function() {
		this.x -= 2;
		// 碰撞检测，检查自己有没有撞到这个鸟
		if(game.bird.R > this.x && 　game.bird.L < this.x + 52) {
			if(game.bird.T < this.dnwnheight || game.bird.B > this.dnwnheight + this.interspace) {
				// 死亡就进入场景4
				game.sm.enter(4);
			}
		}
		// 加分
		if(game.bird.R > this.x + 52 && !this.alreadyPass) {
			// 顺利通过了
			game.score++;
			// 标记为已经通过了
			this.alreadyPass = true;
		}
		// 检测这个管子是否已经出了视口,如果是,要从数组中删除这个管子
		if(this.x < -52){
			for (var i = 0; i < game.pipe_Arr.length; i++) {
				if(game.pipe_Arr[i] === this){
					game.pipe_Arr.splice(i,1);
				}
			}
		}

	}
	// 渲染
	Pipe.prototype.render = function() {
		// 上面的管子，开口向下
		game.ctx.drawImage(this.imagedown, 0, this.picheight - this.dnwnheight, 52, this.dnwnheight, this.x, 0, 52, this.dnwnheight);
		// 下面的管子，开口向上
		game.ctx.drawImage(this.imageup, 0, 0, 52, this.upheight, this.x, this.dnwnheight + this.interspace, 52, this.upheight);
	}

})();